const web = require("../../module/web"), loger = require("../../module/loger");
let bl = 0;

module.exports.run = (ph)=>{
	if(ph) global.sdObj.ud[3] = ph;
	bl = 0;
	
	web.run((w)=>{
		let uf = w.window.document.getElementById("userinfo");
		if(uf){
			let al = uf.getElementsByTagName("a");
			for(let i=0;i<al.length;i++){
				if(al[i].innerHTML == '登录'){
					// al[i].click();
					// return;
				}else if(al[i].innerHTML == '注册'){
					al[i].click();
					return;
				}
			}				
		}
	}, (w)=>{
		//loger.info(global.sdObj.ud);
		let sperr = w.window.document.getElementsByClassName("quc-tip quc-tip-error");
		for(let i=0;i<sperr.length;i++){
			if(sperr[i].innerHTML.indexOf("该手机号已经注册") != -1){
				global.sdObj.end = 1030;
				loger.info("1030");
				return true;
			}else if(sperr[i].innerHTML.indexOf("网络错误") != -1){
				
			}
		}
		//loger.info("enter");
		//输入信息
		let inp = w.window.document.getElementsByName("password");
		if(inp && inp[0]) inp[0].value = global.sdObj.ud[10];
		else return;
		inp = w.window.document.getElementsByName("account");
		if(inp && inp[0]){
			inp[0].value = global.sdObj.ud[3];
			w.window.$(inp[0]).blur();
			bl++;
		}else{
			return;
		}
	
		//截图，验证吗是网页加载完后才加载的所以要延迟
		if(bl > 2){
			web.getImg("tmp", 5e3, ()=>{ 
				global.sdObj.end = 0;
				loger.info("tmp");
			})			
			return true;			
		}
	})
}